package com.twang.stock.task;

import com.alibaba.fastjson.JSONObject;
import com.twang.stock.dto.StockMinutesMessage;
import com.twang.stock.mapper.CompanyCodeInfoMapper;
import com.twang.stock.mapper.CompanyStockMapper;
import com.twang.stock.mapper.CompanyStockMinutesMapper;
import com.twang.stock.redis.RedisUtil;
import com.twang.stock.rocketMq.RocketMQProducer;
import com.twang.stock.service.CompanyStockMinutesService;
import com.twang.stock.service.jinyan.CommonService;
import com.twang.stock.service.jinyan.HolidayService;
import com.twang.stock.email.SendmailService;

import com.twang.stock.task.old.BaseTask;
import com.twang.stock.threadPool.AsycTaskExecutorConfig;
import com.twang.stock.utils.date.DateUtils;
import com.twang.stock.utils.date.HolidayCopy;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @param ：
 * 每日14：57更新
 * 即时--http://data.10jqka.com.cn/funds/gnzjl/ajax/1/free/1/
 *             3日：http://data.10jqka.com.cn/funds/gnzjl/board/3/ajax/1/free/1/
 *             5日：http://data.10jqka.com.cn/funds/gnzjl/board/5/ajax/1/free/1/
 *           明细：http://q.10jqka.com.cn/gn/detail/code/300845/
 */
@Slf4j
@Component
public class KaiPanLaZiJinTask extends BaseTask {

    @Autowired
    private RocketMQProducer rocketMQProducer;

    @Autowired
    private HolidayService holidayService;

    @Autowired
    private AsycTaskExecutorConfig asycTaskExecutorConfig;

    @Scheduled(cron = "0 0/30 9,10,11,12,13,14,15 * * ?")
    public void excute() throws InterruptedException {
        if (!holidayService.isWorkDay(HolidayCopy.getRealToday())) {
            log.info(">>>>>>>>>>>> 开盘啦资金净额  message={}", HolidayCopy.getHHmmss().substring(8, 12));
            return;
        }
        if (DateUtils.JudgeTime("00:09:25", "11:31:00") || DateUtils.JudgeTime("12:59:00", "15:01:00")) {
            asycTaskExecutorConfig.taskQueueExecutor().execute(() -> {
                try {
                    开盘啦资金净额();
                } catch (Exception e) {
                    log.info("error = {}", e);
                }
                log.info("==========> 开盘啦资金净额  KaiPanLaZiJinTask end!");
            });
        }

    }

    public void 开盘啦资金净额() throws InterruptedException {
        StockMinutesMessage message = new StockMinutesMessage();
        message.setMinutes(HolidayCopy.getHHmmss().substring(8, 12));
        message.setDate(HolidayCopy.getRealToday());
        message.setType(StockMinutesMessage.TYPE_ZI_JING_JIN_E);
        log.info(">>>>>>>>>>>> 开盘啦资金净额  message={}", JSONObject.toJSONString(message));
        Thread.sleep(60000);//等一分钟触发 抓到最新的数据
        rocketMQProducer.sendOneWay(JSONObject.toJSONString(message));
    }

}
